package summary;

/**
 * @Author: 海琳琦
 * @Date: 2022/7/2 20:28
 */
public class Title338 {

    public static int[] countBits(int n) {
        int[] result = new int[n + 1];
        for (int i = 1; i <= n; i++) {
            result[i] = getOneCount(i);
        }
        return result;
    }

    private static int getOneCount(int n) {
        int count = 0;
        while (n != 0) {
            count += n & 1;
            n = n >> 1;
        }
        return count;
    }

    public static int[] countBits2(int n) {
        int[] dp = new int[n + 1];
        for (int i = 1; i <= n; i++) {
            dp[i] = dp[i >> 1] + (i & 1);
        }
        return dp;
    }

    public static void main(String[] args) {
        countBits(2);
    }
}
